/**
 * @file arpscanner.h
 * @brief
 * @version 0.1
 *
 * Copyright (C) Vicoretek, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * Written by shaocheng.zhou <shaocheng.zhou@vicoretek.com>, June 2025
 */

#ifndef HOSTDETECTOR_H
#define HOSTDETECTOR_H

#include <pcap.h>

#include <QList>
#include <QMap>
#include <QObject>
#include <QThread>
#include "arplistener.h"
#include "arprequstsender.h"

#include "arp_types.h"

class HostDetector : public QThread
{
    Q_OBJECT
  public:
    explicit HostDetector(QObject* parent = nullptr);

    ~HostDetector();

    bool init();

    void uninit();

    QList<EthDev> list_all();
    
    void listen_dev(int dev_index);
  protected:
    void run() override;

  signals:
    void eth_dev_found(QList<EthDev>);

  private:
    void init_pcap();

    void scan(const QString& interface_name);

  private:
    pcap_if_t*    alldevs_ { nullptr };
    QList<EthDev> eth_devs_;
    QMap<QString, std::shared_ptr<ArpListener>> arp_listeners_;
    QMap<QString, std::shared_ptr<ArpRequstSender>> arp_senders_;
};

#endif  // HOSTDETECTOR_H
